/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package StaffLoginManager;

import java.sql.*;
import DBManager.DBConnection;
/**
 *
 * @author Alex
 */
public class StaffLoginManager {
    public boolean LoginUser(String username, String password)
    {
        boolean result = false;

        try{
            //get connection
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();

            //Construct SQL Query
           PreparedStatement pstmt= conn.prepareStatement("select * from admin where username=? and password=?");

            //append values for the parameters
            int i=1;
             pstmt.setString(i++, username);
              pstmt.setString(i++, password);



            //execute SQL statement
        ResultSet rs= pstmt.executeQuery();

            //check if there is a data inside rs

 while(rs.next())
 {
 result=true;
 }
 conn.close();
        }
        catch(SQLException ex){ex.printStackTrace();}

        return result;
    }
     
     

   

      public boolean LoginAdmin(String admin, String adminpass)
    {
        boolean result = false;

        try{
            //get connection
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();

            //Construct SQL Query
           PreparedStatement pstmt= conn.prepareStatement("call getAdmin(?,?)");

            //append values for the parameters
            int i=1;
             pstmt.setString(i++, admin);
              pstmt.setString(i++, adminpass);



            //execute SQL statement
        ResultSet rs= pstmt.executeQuery();

            //check if there is a data inside rs

 while(rs.next())
 {
 result=true;
 }
 conn.close();
        }
        catch(SQLException ex){ex.printStackTrace();}

        return result;
    }
     
      public boolean LoginManager(String manager, String managerpass)
    {
        boolean result = false;

        try{
            //get connection
            DBConnection db = new DBConnection();
            Connection conn = db.getConnection();

            //Construct SQL Query
           PreparedStatement pstmt= conn.prepareStatement("call getmanager(?,?)");

            //append values for the parameters
            int i=1;
            
             pstmt.setString(i++, manager);
             pstmt.setString(i++, managerpass);

            //execute SQL statement
            ResultSet rs= pstmt.executeQuery();

            //check if there is a data inside rs

            while(rs.next()){
            result=true;
            }
            conn.close();
            }
            catch(SQLException ex){ex.printStackTrace();}

        return result;
}
}